﻿<navigation:Page x:Class="RIAExample.Views.ProdutoListar" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="ProdutoListar Page" 
                 
           xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
           xmlns:my="clr-namespace:RIAExample.Web.Models" 
           xmlns:my1="clr-namespace:RIAExample.Web.Services" 
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:my2="clr-namespace:RIAExample.Controls">
    <Grid x:Name="LayoutRoot">
        <riaControls:DomainDataSource AutoLoad="True" LoadedData="produtoDomainDataSource_LoadedData" 
                Name="produtoDomainDataSource" LoadSize="{Binding ElementName=DataPager, Path=PageSize}" QueryName="GetProdutoesQuery">
            <riaControls:DomainDataSource.DomainContext>
                <my1:SupermercadoDomainContext />
            </riaControls:DomainDataSource.DomainContext>
            
            <riaControls:DomainDataSource.SortDescriptors>
                <riaControls:SortDescriptor PropertyPath="Preco" Direction="Ascending"/>
            </riaControls:DomainDataSource.SortDescriptors>
            
            <riaControls:DomainDataSource.GroupDescriptors>
                <riaControls:GroupDescriptor PropertyPath="SupermercadoID"/>
            </riaControls:DomainDataSource.GroupDescriptors>

            <riaControls:DomainDataSource.FilterDescriptors>
                <riaControls:FilterDescriptor
                    PropertyPath="Descricao"
                    Operator="Contains"
                    IgnoredValue=""
                    Value="{Binding ElementName=txtNomeProduto, Path=Text, Mode=TwoWay}"/>
                <riaControls:FilterDescriptor
                    PropertyPath="Preco"
                    Operator="IsLessThanOrEqualTo"
                    IgnoredValue=""
                    Value="{Binding ElementName=txtPreco, Path=Text, Mode=TwoWay}"/>
            </riaControls:DomainDataSource.FilterDescriptors>

        </riaControls:DomainDataSource>

        <Grid HorizontalAlignment="Left" Name="Filtros" Width="640" Margin="0,0,0,417">
            <sdk:Label Height="28" HorizontalAlignment="Left" Margin="18,6,0,0" Name="label1" VerticalAlignment="Top" Width="120" Content="Produto:" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="18,24,0,0" Name="txtNomeProduto" VerticalAlignment="Top" Width="207" />
            <sdk:Label Content="Preço menor que:" Height="28" HorizontalAlignment="Left" Margin="231,6,0,0" Name="label2" VerticalAlignment="Top" Width="120" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="231,24,0,0" Name="txtPreco" VerticalAlignment="Top" Width="207" />
        </Grid>

        <sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ElementName=produtoDomainDataSource, Path=Data}" 
                      Name="produtoDataGrid" Margin="0,69,0,36">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn x:Name="descricaoColumn" Binding="{Binding Path=Descricao}" Header="Descricao"/>
                <sdk:DataGridTextColumn x:Name="precoColumn" Binding="{Binding Path=Preco}" Header="Preco" />
                <sdk:DataGridTextColumn x:Name="produtoIDColumn" Binding="{Binding Path=ProdutoID, Mode=OneWay}" Header="Produto ID" />
                <sdk:DataGridTextColumn x:Name="supermercadoIDColumn" Binding="{Binding Path=Supermercado.Nome}" Header="Nome do Supermercado"/>
                <sdk:DataGridTemplateColumn x:Name="editColumn">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Editar" Click="EditButton_Click" />
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        
        <sdk:DataPager Name="DataPager" 
                Margin="5,5,5,5"
                Source="{Binding Data, ElementName=produtoDomainDataSource}"
                PageSize="20" 
                Height="25" 
                VerticalAlignment="Bottom"/>
        <my2:BusyIndicator x:Name="BusyIndicator" BusyContent="Aguarde..."
                IsBusy="{Binding ElementName=produtoDomainDataSource, Path=IsBusy}"  />
        <Button Content="Novo Produto" Height="23" HorizontalAlignment="Left" 
                Margin="486,24,0,0" Name="btnEdicaoProduto" VerticalAlignment="Top" 
                Width="118" Click="btnEdicaoProduto_Click" />
    </Grid>
</navigation:Page>
